package thread;

import lombok.SneakyThrows;

/**
 * @description:
 * @author: jichao
 * @date: 2021/5/11 15:52
 */
public class MyThread implements Runnable {

    private String name;

    public MyThread(String name) {
        this.name = name;
    }

    @SneakyThrows
    @Override
    public synchronized void run() {
        for (int i = 0; i < 10; i++) {
            Thread.sleep(2000) ;
            System.out.println(name + "运行，i = " + i);
        }
    }
}

class RunnableDemo01 {
    public static void main(String args[]) {
        MyThread mt1 = new MyThread("线程A ");    // 实例化对象
        Thread t1 = new Thread(mt1);       // 实例化Thread类对象
        t1.start();// 启动多线程
    }
}
